<?php

    function setsession($sess, $message = '') {
        if ($message == '') unset($_SESSION[$sess]);
        else $_SESSION[$sess] = $message;
    }
    
    function getsession($sess) {
        return $_SESSION[$sess];
    }
    
    function redirect($url) {
        header("Location: ".$url);
        exit(-1);
    }

    function view($file) {
        return "view/$file.php";
    }
    
    function logged_admin()
    {
        if(isset($_COOKIE['adminid']) && isset($_COOKIE['adminip']) && isset($_COOKIE['adminsid']))
        {
            setsession('aid',$_COOKIE['adminid']);
            setsession('aip',$_COOKIE['adminip']);
            setsession('asession_id',$_COOKIE['adminsid']);
            return true;
        }

        if (!isset($_SESSION['asession_id']))
            return false;
        return true;
    }